package com.mq.rabbitmq.topic.demo2;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;

public class ATopicRabbitConfig {

    public final static String message = "topic.message";
    public final static String messages = "topic.messages";

    public final static String exchange="exchange";

    @Bean
    public Queue queueMessage() {
        return new Queue(ATopicRabbitConfig.message);
    }

    @Bean
    public Queue queueMessages() {
        return new Queue(ATopicRabbitConfig.messages);
    }

    @Bean
    TopicExchange exchange() {
        return new TopicExchange("exchange");
    }

    @Bean
    Binding bindingExchangeMessage(TopicExchange exchange) {
        return BindingBuilder.bind(queueMessage()).to(exchange).with("topic.message");
    }

    @Bean
    Binding bindingExchangeMessages(TopicExchange exchange) {
        return BindingBuilder.bind(queueMessages()).to(exchange).with("topic.#");
    }

//    /**
//     * 如果默认有rabbitListener 监听，这个就不会执行了，
//     * 只有默认没有那个监听，这个才会执行
//     * @param connectionFactory
//     * @return
//     */
//    @Bean
//    public SimpleMessageListenerContainer messageContainerTest(ConnectionFactory connectionFactory) {
//        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
//        container.setQueues(new Queue(TopicRabbitConfig.messages));
//        container.setExposeListenerChannel(true);
//        container.setMaxConcurrentConsumers(1);
//        container.setConcurrentConsumers(1);
//        container.setMessageListener(new ChannelAwareMessageListener() {
//            @Override
//            public void onMessage(Message message, Channel channel) throws Exception {
//                byte[] body = message.getBody();
//                System.out.println("helloreceive3 <<<<<SimpleMessageListenerContainer HelloReceive3  232323 是多少 receive msg queue: " + new String(body));
//                //channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); //确认消息成功消费
//            }
//        });
//        return container;
//    }


}